package com.wangfei.lecture.logback;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyApp3 {
    final static Logger logger = LoggerFactory.getLogger(MyApp3.class);
    private static final String fileName = "/Users/wangfei/IdeaProjects/demo/src/main/java/com/wangfei/lecture/logback/Sample4.xml";
    public static void main(String[] args) {
        // Invoking JoranConfigurator directly
        // assume SLF4J is bound to logback in the current environment
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator joranConfigurator = new JoranConfigurator();
        joranConfigurator.setContext(context);
        context.reset();

        try {
            joranConfigurator.doConfigure(fileName);
        } catch (JoranException e) {
            throw new RuntimeException(e);
        }

//        StatusPrinter.printInCaseOfErrorsOrWarnings(context);

        logger.info("Entering application.");

        Foo foo = new Foo();
        foo.doIt();
        logger.info("Exiting application.");
    }
}
